home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Leser 19 / Amiga Plus Leser CD 19.iso / Tools / Freeware / ttengine-5.0 / Examples / FontNames / names.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-11-05  |  5.8 KB  |  157 lines

  1. /* test ttrender */
  2.  
  3. #define __NOLIBBASE__
  4.  
  5. #include <proto/dos.h>
  6. #include <proto/exec.h>
  7. #include <proto/intuition.h>
  8. #include <proto/graphics.h>
  9. #include <proto/ttengine.h>
  10. #include <proto/asl.h>
  11.  
  12. #include <libraries/ttengine.h>
  13.  
  14. extern struct Library *SysBase, *DOSBase;
  15.  
  16. /*----------------------------------------------------------------------------------------------------*/
  17.  
  18. static STRPTR get_font_name(struct Library *AslBase)
  19.   {
  20.     struct FileRequester *freq;
  21.     STRPTR name = NULL;
  22.  
  23.     if (freq = AllocAslRequestTags(ASL_FileRequest, TAG_END))
  24.       {
  25.         if (AslRequestTags(freq,
  26.           ASLFR_TitleText, (ULONG)"Select TrueType font",
  27.           ASLFR_InitialDrawer, (ULONG)"FONTS:",
  28.           ASLFR_DoPatterns, TRUE,
  29.           ASLFR_InitialPattern, (ULONG)"#?.ttf",
  30.           ASLFR_RejectIcons, TRUE,
  31.           TAG_END))
  32.           {
  33.             ULONG namelen = strlen(freq->fr_File) + strlen(freq->fr_Drawer) + 4;
  34.  
  35.             if (name = AllocVec(namelen + 1, MEMF_ANY | MEMF_CLEAR))
  36.               {
  37.                 strncpy(name, freq->fr_Drawer, namelen);
  38.                 AddPart(name, freq->fr_File, namelen);
  39.               }
  40.           }
  41.         FreeAslRequest(freq);
  42.       }
  43.     return name;
  44.   }
  45.  
  46. /*----------------------------------------------------------------------------------------------------*/
  47.  
  48. static VOID free_font_name(STRPTR name)
  49.   {
  50.     if (name) FreeVec(name);
  51.   }
  52.  
  53. /*----------------------------------------------------------------------------------------------------*/
  54.  
  55. int Main (void)
  56.   {
  57.     struct Library *TTEngineBase, *IntuitionBase, *GfxBase, *AslBase;
  58.     struct Window *win;
  59.     STRPTR fontname;
  60.     APTR font;
  61.  
  62.     if (GfxBase = OpenLibrary("graphics.library", 39))
  63.       {
  64.         if (IntuitionBase = OpenLibrary("intuition.library", 39))
  65.           {
  66.             if (AslBase = OpenLibrary("asl.library", 38))
  67.               {
  68.                 if (fontname = get_font_name(AslBase))
  69.                   {
  70.                     if (TTEngineBase = OpenLibrary("ttengine.library", 4))
  71.                       {
  72.                         if (win = OpenWindowTags(NULL,
  73.                           WA_Top, 25,
  74.                           WA_Left, 0,
  75.                           WA_Width, 400,
  76.                           WA_Height, 100,
  77.                           WA_CloseGadget, TRUE,
  78.                           WA_DragBar, TRUE,
  79.                           WA_DepthGadget, TRUE,
  80.                           WA_IDCMP, IDCMP_CLOSEWINDOW,
  81.                           WA_Title, (ULONG)"TTEngine font names",
  82.                           TAG_END))
  83.                           {
  84.                             ULONG sigmask, signals;
  85.                             BOOL running = TRUE;
  86.                             struct RastPort *rp = win->RPort;
  87.  
  88.                             if (font = TT_OpenFont(
  89.                               TT_FontFile, (ULONG)fontname,
  90.                               TT_FontSize, 18,
  91.                             TAG_END))
  92.                               {
  93.                                 STRPTR family, subfamily, fullname;
  94.  
  95.                                 free_font_name(fontname);
  96.  
  97.                                 if (TT_SetFont(rp, font))
  98.                                   {
  99.                                     TT_SetAttrs(rp,
  100.                                       TT_Window, (ULONG)win,
  101.                                       TT_Encoding, TT_Encoding_Default,
  102.                                       TT_Antialias, TT_Antialias_On,
  103.                                     TAG_END);
  104.  
  105.                                     TT_GetAttrs(rp,
  106.                                       TT_FamilyName, (ULONG)&family,
  107.                                       TT_SubfamilyName, (ULONG)&subfamily,
  108.                                       TT_FontName, (ULONG)&fullname,
  109.                                     TAG_END);
  110.  
  111.                                     SetAPen(rp, 1);
  112.                                     SetDrMd(rp, JAM1);
  113.  
  114.                                     Move(rp, 10, 36);
  115.                                     TT_Text(rp, family, strlen(family));
  116.                                     Move(rp, 10, 54);
  117.                                     TT_Text(rp, subfamily, strlen(subfamily));
  118.                                     Move(rp, 10, 72);
  119.                                     TT_Text(rp, fullname, strlen(fullname));
  120.                                   }
  121.                                 else PutStr("TT_SetFont() failed.\n");
  122.                                 TT_CloseFont(font);
  123.                               }
  124.                             else PutStr("Font open failed.\n");
  125.  
  126.                             sigmask = SIGBREAKF_CTRL_C | (1 << win->UserPort->mp_SigBit);
  127.                             while (running)
  128.                               {
  129.                                 signals = Wait(sigmask);
  130.                                 if (signals & SIGBREAKF_CTRL_C) running = FALSE;
  131.                                 if (signals & (1 << win->UserPort->mp_SigBit))
  132.                                   {
  133.                                     struct IntuiMessage *imsg;
  134.  
  135.                                     while (imsg = (struct IntuiMessage*)GetMsg(win->UserPort))
  136.                                       {
  137.                                         if (imsg->Class == IDCMP_CLOSEWINDOW) running = FALSE;
  138.                                         ReplyMsg((struct Message*)imsg);
  139.                                       }
  140.                                   }
  141.                               }
  142.                             TT_DoneRastPort(rp);
  143.                             CloseWindow(win);
  144.                           }
  145.                         CloseLibrary(TTEngineBase);
  146.                       }
  147. //                    free_font_name(fontname);
  148.                   }
  149.                 CloseLibrary(AslBase);
  150.               }
  151.             CloseLibrary(IntuitionBase);
  152.           }
  153.         CloseLibrary(GfxBase);
  154.       }
  155.     return 0;
  156.   }
  157.